package org.kpli.jak.db.sec;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class UpdatePerson {

	static SessionFactory sessionFactory;

	static Session session;

	public static void main(String[] args) {

		sessionFactory = new Configuration().configure().buildSessionFactory();

		Session session = sessionFactory.openSession();

		Transaction transaction = session.beginTransaction();
		Person person = (Person) session.load(Person.class, 1);
		person.setNama("arya");
		transaction.commit();

		createQuery(session);

	}

	@SuppressWarnings("unchecked")
	public static void createQuery(Session session) {
		Query query = session.createQuery("from Person");

		List<Person> list = query.list();

		java.util.Iterator<Person> iter = list.iterator();

		while (iter.hasNext()) {

			Person person = iter.next();
			System.out.println("id " + person.getId());
			System.out.println("nama " + person.getNama());
			System.out.println("alamat " + person.getAlamat());
		}

	}

}
